from math import inf
from typing import List


class Solution:
    def check(self, nums: List[int], l: int, r: int) -> bool:
        n = r - l + 1
        if n == 2:
            return True
        minval, maxval = inf, -inf
        se = set()
        for i in range(l, r + 1):
            se.add(nums[i])
            minval = min(minval, nums[i])
            maxval = max(maxval, nums[i])
        if (maxval - minval) % (n - 1) != 0:
            return False
        d = (maxval - minval) // (n - 1)
        for i in range(1, n):
            if minval + i * d not in se:
                return False
        return True

    def checkArithmeticSubarrays(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]:
        ans = []
        for i in range(len(l)):
            ans.append(self.check(nums, l[i], r[i]))
        return ans

    def checkArithmeticSubarrays2(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]:
        ans = []
        for left, right in zip(l, r):
            t = nums[left: right + 1]
            t.sort()
            if len(t) < 3: 
                ans.append(True)
            else:
                x = t[1] - t[0]
                for i in range(2, len(t)):
                    if t[i] - t[i - 1] != x:
                        ans.append(False)
                        break
                else:
                    ans.append(True)
        return ans
    